<template>
	<view class="contenter">
		<!-- <view class="block__title" @click="addMumber">添加多个成员</view> -->
		<view class="box" v-for="(item,index) in form_data" :key="index">
			<view class="block__title">基本信息</view>
			<view class="cu-form-group">
				<view class="title">姓名</view>
				<input placeholder="请输入成员姓名">{{item.name}}</input>
			</view>
			<view class="cu-form-group">
				<view class="title">类别</view>
				<picker bindchange="PickerChange" :value="ownerType" :range="houseType" @change="ownerChange">
					<view class="picker" v-if="memberType ==1">
						<text v-if="choiceType == '0'">业主成员</text>
						<text v-else-if="choiceType == '1'">租户户住</text>
						<text v-else-if="choiceType == '2'">租户成员</text>
					</view>
					<view class="picker" v-if="memberType ==3">
						<text v-if="choiceType == '1'">租户成员</text>
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">身份证</view>
				<input placeholder="请输入成员身份证">{{item.idCard}}</input>
			</view>
			<view class="cu-form-group">
				<view class="title">手机号</view>
				<input  placeholder="请输入成员手机号">{{item.phoneNumber}}</input>
			</view>




			<view class="content_box">
				<button class="cu-btn bg-green margin-tb-sm lg" @click="submitOwnerMember()">提交</button>
			</view>
		</view>
	</view>
</template>

<script>
	// pages/enterCommunity/enterCommunity.js
	import context from '../../lib/java110/Java110Context.js';
	import {
		isIDCard,
		checkPhoneNumber
	} from '../../lib/java110/utils/StringUtil.js'
	const constant = context.constant;
	const factory = context.factory;

	export default {
		data() {
			return {
				form_data: [
					{
						"name":"",
						"idCard":"",
						"phoneNumber":"",
						
					}
				],
				"houseType": ["业主成员", "租户户住", "租户成员"],
				"choiceType": "0", //默认成员身份类型
				"ownerId": "11",
				"memberId": "1",
				"communityId": "111",
				memberType: '', //身份类型
			};
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			let _that = this;
			context.onLoad(options);
			_that.memberType = options.ownerMemberType;
			console.log("1是业主添加", _that.memberType)
			// context.onLoad(options);
			// context.getOwner(function(_owner) {
			// 	_that.ownerId = _owner.memberId;
			// 	_that.communityId = _owner.communityId;
			// });
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		methods: {
			submitOwnerMember: function(e) {
				console.log('this', this);
				let obj = {
					"sex": this.form_data.sex,
					"name": this.form_data[0].name,
					"phoneNumber": this.form_data[0].phoneNumber,
					"ownerId": this.ownerId,
					"userId": this.userId,
					"ownerTypeCd": this.ownerTypeCd,
					"age": this.age,
					"memberId": this.form_data.memberId,
					"communityId": this.communityId,
					"idCard": this.form_data.idCard,
					"choiceType": this.form_data.choiceType
				}
				let msg = "";
				if (obj.name == "") {
					msg = "请填写成员姓名";
				} else if (obj.age == "") {
					msg = "请填写成员年龄";
				} else if (obj.idCard == "") {
					msg = "请填写成员身份证号";
				} else if (obj.phoneNumber == "") {
					msg = "请填写成员手机号";
				}
				if (msg != "") {
					uni.showToast({
						title: msg,
						icon: 'none',
						duration: 2000
					});
				} else {
					uni.showLoading({
						title: '提交中',
					});
					console.log("提交数据", obj);
					context.request({
						url: constant.url.saveOwner,
						header: context.getHeaders(),
						method: "POST",
						data: obj,
						// data:obj, //动态数据
						success: function(res) {
							console.log(res, 99999);

							if (res.statusCode == 200 && res.data.code == 0) {
								uni.hideLoading();
								uni.navigateBack();
								return;
							}

							uni.hideLoading();
							uni.showToast({
								title: res.data.msg,
								icon: 'none',
								duration: 2000
							});
						},
						fail: function(e) {
							uni.hideLoading();
							uni.showToast({
								title: "服务器异常了",
								icon: 'none',
								duration: 2000
							})
						}
					});
				}

			},
			sexChange: function(e) {
				console.log("onConfirm", e);
				this.sex = e.detail.value;
			},
			ownerChange: function(e) {
				console.log("onConfirm", e);
				this.form_data.choiceType = e.detail.value;
			},
			addMumber() {
				let num = 0;
				this.num = num+1;
				this.form_data.push("num")
			}
		}
	};
</script>
<style scoped lang="scss">
	.contenter{
		width: 100%;
		height: calc(100vh - 100rpx);
		overflow: auto;
	}
	.block__title {
		margin: 0;
		font-weight: 400;
		font-size: 14px;
		color: rgba(69, 90, 100, .6);
		padding: 40rpx 30rpx 20rpx;
	}

	.button_up_blank {
		height: 40rpx;
	}

	.content_box {
		position: fixed;
		bottom: 0rpx;
		height: 100rpx;
		width: 100%;
		display: flex;
		background-color: white;
		justify-content: center;
		align-items: center;

		button {
			width: 400rpx;
			height: 70rpx;
			margin-top: 15rpx;
			border-radius: 30rpx;
		}
	}
</style>
